package com.lai.lai.utils;

import org.springframework.beans.BeansException;
import org.springframework.context.ApplicationContext;
import org.springframework.context.ApplicationContextAware;
import org.springframework.stereotype.Component;

//用来获取工厂
@Component
public class ApplicationContextUtils implements ApplicationContextAware{
    private static ApplicationContext applicationContext;
    //将创建好的工厂传给这个类
    @Override
    public void setApplicationContext(ApplicationContext applicationContext) throws BeansException {
            this.applicationContext = applicationContext;
    }

    //提供在工厂中获取类的方法
    public static Object getBean(String beanName){
            return applicationContext.getBean(beanName);
    }
}
